{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/NAS/xzhang/source/python/Extension_of_Neighbor-based_Link_Prediction_Methods\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "os.chdir(\"../\")\n",
    "print(os.getcwd())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/NAS/xzhang/anaconda3/envs/gs37/lib/python3.7/site-packages/ipykernel_launcher.py:10: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version.\n",
      "\n",
      "\n",
      "  # Remove the CWD from sys.path while we load stuff.\n"
     ]
    }
   ],
   "source": [
    "from Data.data_loader import DataLoader\n",
    "import pandas as pd\n",
    "import Estimation.ext_measure as ext\n",
    "\n",
    "\n",
    "os.chdir(\"Data\")\n",
    "save_path = \"../Data/HepTh.csv\"\n",
    "\n",
    "\n",
    "loader = DataLoader(944175600)\n",
    "loader.read_data()\n",
    "graph = loader.graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████| 6798/6798 [19:56<00:00,  5.68it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "ext.calc_measure(graph, graph.start_time)\n",
    "\n",
    "print(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "columns = ['vertices']\n",
    "for index in range(9):\n",
    "    columns.append(\"score\"+str(index))\n",
    "columns.append(\"has_edge\")\n",
    "df = pd.DataFrame(columns=columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--Return--\n",
      "None\n",
      "> \u001B[0;32m/tmp/ipykernel_1355314/3770527320.py\u001B[0m(4)\u001B[0;36m<module>\u001B[0;34m()\u001B[0m\n",
      "\u001B[0;32m      2 \u001B[0;31m\u001B[0;32mimport\u001B[0m \u001B[0mpdb\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m      3 \u001B[0;31m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m----> 4 \u001B[0;31m\u001B[0mpdb\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mset_trace\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m      5 \u001B[0;31m\u001B[0;32mfor\u001B[0m \u001B[0mvertex\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mtqdm\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mgraph\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mvertices\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m      6 \u001B[0;31m    \u001B[0mvertices\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mlist\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mmeasures\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mkeys\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\n",
      "Breakpoint 11 at /tmp/ipykernel_1355314/3770527320.py:12\n",
      "Breakpoint 12 at /tmp/ipykernel_1355314/3770527320.py:15\n",
      "['2-2824']\n",
      "None\n",
      "> \u001B[0;32m/tmp/ipykernel_1355314/3770527320.py\u001B[0m(12)\u001B[0;36m<module>\u001B[0;34m()\u001B[0m\n",
      "\u001B[0;32m     10 \u001B[0;31m        \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalues\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m     11 \u001B[0;31m        \u001B[0mscores\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget_measure\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[1;31m11\u001B[0;32m-> 12 \u001B[0;31m        \u001B[0;32mfor\u001B[0m \u001B[0mscore\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mscores\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m     13 \u001B[0;31m            \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mscore\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m     14 \u001B[0;31m        \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontact\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\n",
      "None\n",
      "> \u001B[0;32m/tmp/ipykernel_1355314/3770527320.py\u001B[0m(12)\u001B[0;36m<module>\u001B[0;34m()\u001B[0m\n",
      "\u001B[0;32m     10 \u001B[0;31m        \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalues\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m     11 \u001B[0;31m        \u001B[0mscores\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget_measure\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[1;31m11\u001B[0;32m-> 12 \u001B[0;31m        \u001B[0;32mfor\u001B[0m \u001B[0mscore\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mscores\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m     13 \u001B[0;31m            \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mscore\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\u001B[0;32m     14 \u001B[0;31m        \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontact\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0m\n",
      "[0, 0, 0, 117.27277689801116, 0, 0, 0, 0, 0]\n",
      "['2-2824', 0]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|                                                  | 0/6798 [00:22<?, ?it/s]\n"
     ]
    },
    {
     "ename": "BdbQuit",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mBdbQuit\u001B[0m                                   Traceback (most recent call last)",
      "\u001B[0;32m/tmp/ipykernel_1355314/3770527320.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m     10\u001B[0m         \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalues\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     11\u001B[0m         \u001B[0mscores\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget_measure\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 12\u001B[0;31m         \u001B[0;32mfor\u001B[0m \u001B[0mscore\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mscores\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m     13\u001B[0m             \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mscore\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     14\u001B[0m         \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontact\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/tmp/ipykernel_1355314/3770527320.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m     10\u001B[0m         \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalues\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     11\u001B[0m         \u001B[0mscores\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget_measure\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 12\u001B[0;31m         \u001B[0;32mfor\u001B[0m \u001B[0mscore\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mscores\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m     13\u001B[0m             \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mscore\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     14\u001B[0m         \u001B[0mvalues\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mappend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mitem\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mvertex\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontact\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/anaconda3/envs/gs37/lib/python3.7/bdb.py\u001B[0m in \u001B[0;36mtrace_dispatch\u001B[0;34m(self, frame, event, arg)\u001B[0m\n\u001B[1;32m     86\u001B[0m             \u001B[0;32mreturn\u001B[0m \u001B[0;31m# None\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     87\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0mevent\u001B[0m \u001B[0;34m==\u001B[0m \u001B[0;34m'line'\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 88\u001B[0;31m             \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdispatch_line\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mframe\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m     89\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0mevent\u001B[0m \u001B[0;34m==\u001B[0m \u001B[0;34m'call'\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     90\u001B[0m             \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdispatch_call\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mframe\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0marg\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/anaconda3/envs/gs37/lib/python3.7/bdb.py\u001B[0m in \u001B[0;36mdispatch_line\u001B[0;34m(self, frame)\u001B[0m\n\u001B[1;32m    111\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mstop_here\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mframe\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32mor\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mbreak_here\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mframe\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    112\u001B[0m             \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0muser_line\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mframe\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 113\u001B[0;31m             \u001B[0;32mif\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mquitting\u001B[0m\u001B[0;34m:\u001B[0m \u001B[0;32mraise\u001B[0m \u001B[0mBdbQuit\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    114\u001B[0m         \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mtrace_dispatch\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    115\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mBdbQuit\u001B[0m: "
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "import pdb\n",
    "\n",
    "pdb.set_trace()\n",
    "for vertex in tqdm(graph.vertices):\n",
    "    vertices = list(vertex.measures.keys())\n",
    "    for item in vertices:\n",
    "        vertex_pair = str(vertex.identity) + '-' + str(item)\n",
    "        values = [vertex_pair]\n",
    "        print(values)\n",
    "        scores = vertex.get_measure(item)\n",
    "        for score in scores:\n",
    "            values.append(score)\n",
    "        values.append(item in vertex.contact)\n",
    "        df = df.append([values])\n",
    "\n",
    "df.to_csv(save_path, index=False)\n",
    "\n",
    "print(1)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "for vertex in graph.vertices:\n",
    "    vertices = list(vertex.measures.keys())\n",
    "    for item in vertices:\n",
    "        vertex_pair = vertex.identity + str(item)\n",
    "        values = [vertex_pair]\n",
    "        scores = vertex.get_measure(item)\n",
    "        for score in scores:\n",
    "            values.append(score)\n",
    "        values.append(item in vertex.contact)\n",
    "        df = df.append([values])\n",
    "\n",
    "df.to_csv(save_path, index=False)\n",
    "\n",
    "print(1)\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}